<!-- <!DOCTYPE html>
<html> -->
<body>
<?php

/* 
数据库操作 具体配置参考网络 问题:help/
*/

$host = "47.96.22.83"; // localhost
$user = "root";
$passwd = "syhjvip-work616-dijfuhGro90F"; //123456

echo "php info -------------------------begin -------------------------------\n<br>";
//echo phpinfo();
echo "php info -------------------------end -------------------------------\n<br>";

// 创建连接
/* $conn = new mysqli($servername, $username, $password);

// 检测连接
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} */

testMysql($host,$user,$passwd);

function testMysql($h,$u,$p): void {
    $link = mysqli_connect($h, $u, $p, "game1", 3306);
    if(!$link) {
        echo "mysql connect fail.<br>";
        return;
    }
    echo "mysql connect like ok.<br>";
    $link->set_charset('UTF8');

    //--------------------------------------------------------------------------------
    $rst = $link->query("select * from d_users limit 33");
    if (!$rst) {
        echo "***************** query users fail.<br>";
    }
    echo "================================== query user n:", $rst->num_rows, "\n<br>";
    echo '
    <table border="1" style="border-collapse: collapse;">
        <tr style="background-color:rgb(16, 201, 124);">
            <th>ID</th>
            <th>昵称</th>
            <th>金币</th>
            <th>奖券</th>
        </tr>';
    $i = 0;
    while ($r = $rst->fetch_assoc()) {
        //echo 'id:'.$r['id'].', name:'.$r['name'].', gold:'.$r['gold'].', cash:'.$r['cash'], "\n<br>";
        $td = '<td>';
        if ($i % 2 == 0) {
            $td = '<td style="background-color:rgba(196, 217, 231, 0.88);">';
        }
        echo '
        <tr>
            '.$td.$r['id'].'</td>
            '.$td.$r['name'].'</td>
            '.$td.$r['gold'].'</td>
            '.$td.$r['cash'].'</td>
        </tr>';
        $i++;
    }
    echo '</table>';

    //--------------------------------------------------------------------------------
    $rst = $link->query("select * from d_rooms limit 33");
    if (!$rst) {
        echo "***************** query rooms fail.<br>";
    }
    echo "================================== query rooms n:", $rst->num_rows."\n<br>";
    echo '
    <table border="1" style="border-collapse: collapse;">
        <tr style="background-color:rgb(109, 116, 216);">
            <th>ID</th>
            <th>奖池</th>
            <th>历史押注</th>
            <th>历史赢取</th>
            <th>创建时间</th>
        </tr>';
    $i = 0;
    while ($r = $rst->fetch_assoc()) {
        /* echo 'id:'.$r['id'].', pool:'.$r['bonus_pool'].', hisbet:'.$r['his_bet'].', hiswin:'
            .$r['his_win'].', create:'.$r['created_at'], "\n<br>"; */
        $td = '<td>';
        if ($i % 2 == 0) {
            $td = '<td style="background-color:rgba(191, 226, 184, 0.88);">';
        }
        echo '
        <tr>
            '.$td.$r['id'].'</td>
            '.$td.$r['bonus_pool'].'</td>
            '.$td.$r['his_bet'].'</td>
            '.$td.$r['his_win'].'</td>
            '.$td.$r['created_at'].'</td>
        </tr>';
        $i++;
    }
    echo '</table>';

    //--------------------------------------------------------------------------------
    $sqls = "DROP table if EXISTS test001;";
    $sqls.= "CREATE table test001 select 0 a, 1 b;";
    $sqls.= "insert into test001 select 44, 321;";
    $sqls.= "call stat_user_day(UNIX_TIMESTAMP('2024-01-10'), UNIX_TIMESTAMP());";
    $link->multi_query($sqls);


    //--------------------------------------------------------------------------------
    $link->close();
}


?>
</body>

<!-- http://47.96.22.83:8187/tphp/tt_mysql.php -->

